import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeptForm, DeptQuery, DeptVO } from './types';

/**
 * 部门树形表格
 *
 * @param queryParams
 */
export function listDepts(queryParams?: DeptQuery): AxiosPromise<DeptVO[]> {
  return request({
    url: '/base/dept/listTree',
    method: 'get',
    params: queryParams,
  });
}

/**
 * 获取部门详情
 *
 * @param id
 */
export function findById(id: string): AxiosPromise<DeptForm> {
  return request({
    url: '/base/dept/findById',
    method: 'get',
    params: {
      id: id,
    },
  });
}

/**
 * 新增部门
 *
 * @param data
 */
export function addDept(data: DeptForm) {
  return request({
    url: '/base/dept/save',
    method: 'post',
    data: data,
  });
}

/**
 *  修改部门
 *
 * @param data
 */
export function updateDept(data: DeptForm) {
  return request({
    url: 'base/dept/save',
    method: 'post',
    data: data,
  });
}

/**
 * 删除部门
 *
 * @param ids
 */
export function deleteDept(ids: string) {
  return request({
    url: '/base/dept/delete',
    method: 'post',
    data: {
      ids: ids.split(','),
    },
  });
}
